package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingcartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api("c端购物车")
public class ShoppingCartController {
    @Autowired
private ShoppingcartService shoppingcartService;
@PostMapping("/add")
    public Result addshoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("添加购物车:{}", shoppingCartDTO);
        shoppingcartService.addshoppingcart(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getshoppingcart() {
      log.info("查看购物车");
      List<ShoppingCart> list=shoppingcartService.listall();
      return Result.success(list);
    }

    @PostMapping("/sub")
    public Result deleteoneshoppingcart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
log.info("购物车商品数量减一:{}", shoppingCartDTO);
shoppingcartService.deleteone(shoppingCartDTO);
return Result.success();
    }

    @DeleteMapping("/clean")
    public Result deleteall(){
    log.info("清空购物车");
    shoppingcartService.deleteall();
    return Result.success();
    }
}
